/**
 * Created by jiaaobo on 16/12/24.
 */

import Util from "util";
import API  from "api";

export default{
  data(){
    return{
        user : {
        },
        agreement : true,
        userServerId : ''

    }
  },

  computed : {
  },

  mounted : function(){
      this.getUserInfo();
  },

  methods : {

    onUpdateUser : function(){

      if(!this.user.userName){
        Util.UI.toast("请输入昵称!");
        return;
      }

      if(!this.agreement){
        Util.UI.toast("请同意用户协议!");
        return;
      }

      if(this.user.isAnonymousChecked){
        this.user.isAnonymous = 1;
      }
      else{
        this.user.isAnonymous = 0;
      }

      console.log(this.user);
      API.biz.updateUserInfo(this.user,{hasLoading : true})
        .then((res)=>{
            Util.UI.toast("保存成功");
            window.getRouter().go(-1);
        });
    },

    getUserInfo : function () {

      API.biz.queryUserDetailInfo()
        .then(res=>{
          this.user = res.bizData;
          this.user.isAnonymousChecked = this.user.isAnonymous == 1 ? true : false;
        });
    },

    changeHead : function(){
      let _this  = this;
      Util.WX.chooseAndUploadImage()
        .then(function(ids){
          console.log(ids);
            let obj  =  ids[0];
            _this.user.userIcon = obj.localId;
            _this.userServerId = obj.serverId;
          },function(err){
            Util.UI.toast(err.desc);
          });
    }

  },
  components:{

  }
}
